<?php 
declare(strict_types=1);
/*
 * @Description: 
 * @Author: franktrue 807615827@qq.com
 * @Date: 2021-07-13 10:56:57
 * @LastEditTime: 2021-07-13 16:41:53
 */
namespace App\Model\Entity;

use Swoft\Db\Annotation\Mapping\Column;
use Swoft\Db\Annotation\Mapping\Entity;
use Swoft\Db\Annotation\Mapping\Id;
use Swoft\Db\Eloquent\Model;

/**
 *
 * Class AccountUser
 *
 * @since 2.0
 *
 * @Entity(table="account_user")
 */
class AccountUser extends Model
{
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    protected const CREATED_AT = 'create_at';

    /**
     * @Id()
     *
     * @Column()
     *
     * @var int|null
     */
    private $id;

    /**
     * @Column()
     *
     * @var string
     */
    private $email;

    /**
     * @Column()
     *
     * @var string
     */
    private $phone;

    /**
     * @Column()
     *
     * @var string
     */
    private $username;

    /**
     * @Column(hidden=true)
     *
     * @var string
     */
    private $password;

    /**
     * @Column(name="create_at")
     *
     * @var int
     */
    private $createAt;

    /**
     * @Column(name="create_ip_at")
     *
     * @var string
     */
    private $createIpAt;

    /**
     * @Column(name="last_login_at")
     *
     * @var int
     */
    private $lastLoginAt;

    /**
     * @Column(name="last_login_ip_at")
     *
     * @var string
     */
    private $lastLoginIpAt;

    /**
     * @Column(name="login_times")
     *
     * @var int
     */
    private $loginTimes;

    /**
     * @Column()
     *
     * @var int
     */
    private $status;

    /**
     * Get the value of id
     *
     * @return  int|null
     */ 
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set the value of id
     *
     * @param  int|null  $id
     *
     * @return  self
     */ 
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    
    /**
     * Get the value of email
     *
     * @return  string
     */ 
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set the value of email
     *
     * @param  string  $email
     *
     * @return  self
     */ 
    public function setEmail(string $email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get the value of phone
     *
     * @return  string
     */ 
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set the value of phone
     *
     * @param  string  $phone
     *
     * @return  self
     */ 
    public function setPhone(string $phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get the value of username
     *
     * @return  string
     */ 
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set the value of username
     *
     * @param  string  $username
     *
     * @return  self
     */ 
    public function setUsername(string $username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get the value of password
     *
     * @return  string
     */ 
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set the value of password
     *
     * @param  string  $password
     *
     * @return  self
     */ 
    public function setPassword(string $password)
    {
        $this->password = bcrypt($password);

        return $this;
    }

    /**
     * Get the value of createAt
     *
     * @return  int
     */ 
    public function getCreateAt()
    {
        return $this->createAt;
    }

    /**
     * Set the value of createAt
     *
     * @param  int  $createAt
     *
     * @return  self
     */ 
    public function setCreateAt(int $createAt)
    {
        $this->createAt = $createAt;

        return $this;
    }

    /**
     * Get the value of createIpAt
     *
     * @return  string
     */ 
    public function getCreateIpAt()
    {
        return $this->createIpAt;
    }

    /**
     * Set the value of createIpAt
     *
     * @param  string  $createIpAt
     *
     * @return  self
     */ 
    public function setCreateIpAt(string $createIpAt)
    {
        $this->createIpAt = $createIpAt;

        return $this;
    }

    /**
     * Get the value of lastLoginAt
     *
     * @return  int
     */ 
    public function getLastLoginAt()
    {
        return $this->lastLoginAt;
    }

    /**
     * Set the value of lastLoginAt
     *
     * @param  int  $lastLoginAt
     *
     * @return  self
     */ 
    public function setLastLoginAt(int $lastLoginAt)
    {
        $this->lastLoginAt = $lastLoginAt;

        return $this;
    }

    /**
     * Get the value of lastLoginIpAt
     *
     * @return  string
     */ 
    public function getLastLoginIpAt()
    {
        return $this->lastLoginIpAt;
    }

    /**
     * Set the value of lastLoginIpAt
     *
     * @param  string  $lastLoginIpAt
     *
     * @return  self
     */ 
    public function setLastLoginIpAt(string $lastLoginIpAt)
    {
        $this->lastLoginIpAt = $lastLoginIpAt;

        return $this;
    }

    /**
     * Get the value of loginTimes
     *
     * @return  int
     */ 
    public function getLoginTimes()
    {
        return $this->loginTimes;
    }

    /**
     * Set the value of loginTimes
     *
     * @param  int  $loginTimes
     *
     * @return  self
     */ 
    public function setLoginTimes(int $loginTimes)
    {
        $this->loginTimes = $loginTimes;

        return $this;
    }

    /**
     * Get the value of status
     *
     * @return  int
     */ 
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set the value of status
     *
     * @param  int  $status
     *
     * @return  self
     */ 
    public function setStatus(int $status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * 判断密码是否正确
     * 
     * @param string $password 密码
     * 
     * @return bool
     */
    public function check($password): bool
    {
        if (strlen($this->password) === 0) {
            return false;
        }

        return password_verify($password, $this->password);
    }
}
